package com.dcloud.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dcloud.core.dsplugin.IDsService;
import com.dcloud.manage.mapper.CollectTaskSqlMapper;
import com.dcloud.manage.service.ICollectTaskSqlService;
import com.dcloud.manage.service.entity.CollectTaskSql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description: 任务sql表
 * @Author: jeecg-boot
 * @Date: 2022-09-07
 * @Version: V1.0
 */
@Service
public class CollectTaskSqlServiceImpl extends ServiceImpl<CollectTaskSqlMapper, CollectTaskSql> implements ICollectTaskSqlService {

    @Autowired
    CollectTaskSqlMapper taskSqlMapper;


    @Autowired
    IDsService iDsService;

    /**
     * @param tid
     * @return com.dcloud.task.domain.entity.TTaskSqlEntity
     * @Description 根据任务id查询任务sql信息
     * @Author shijf
     * @Date 17:05 2022/7/12
     */
    @Override
    public CollectTaskSql queryTaskSqlByTaskId(Integer tid) {
        return taskSqlMapper.selectOne(new QueryWrapper<CollectTaskSql>().eq("task_tid", tid));
    }

    /**
     * @param tid 任务sqltid
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @Author shijf
     * @Description 根据任务sqlid即席查询
     * @Date 14:27 2023/5/25
     **/
    @Override
    public List<Map<String, Object>> jxSelect(String tid) throws ClassNotFoundException, InstantiationException, IllegalAccessException {

        CollectTaskSql collectTaskSql = taskSqlMapper.selectById(tid);
        String sql = collectTaskSql.getTaskSql();
        Integer sourceId = collectTaskSql.getSourceId();
        Long limit = 10l;
        List<Map<String, Object>> result = iDsService.selectSqlBySourceId(sql, sourceId, limit);
        return result;
    }
}